package b.f;

import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Objects;

/* compiled from: LruCache */
public class f<K, V> {
    public final LinkedHashMap<K, V> a;
    public int b;
    public int c;
    public int d;
    public int e;
    public int f;
    public int g;

    public f(int i) {
        if (i > 0) {
            this.c = i;
            this.a = new LinkedHashMap(0, 0.75f, true);
            return;
        }
        throw new IllegalArgumentException("maxSize <= 0");
    }

    public final V a(K k) {
        Objects.requireNonNull(k, "key == null");
        synchronized (this) {
            Object obj = this.a.get(k);
            if (obj != null) {
                this.f++;
                return obj;
            }
            this.g++;
            return null;
        }
    }

    public final V b(K k, V v) {
        if (k == null || v == null) {
            throw new NullPointerException("key == null || value == null");
        }
        Object put;
        synchronized (this) {
            this.d++;
            this.b++;
            put = this.a.put(k, v);
            if (put != null) {
                this.b--;
            }
        }
        c(this.c);
        return put;
    }

    /* JADX WARNING: Missing block: B:19:0x0068, code skipped:
            throw new java.lang.IllegalStateException(r0.toString());
     */
    public void c(int r3) {
        /*
        r2 = this;
    L_0x0000:
        monitor-enter(r2);
        r0 = r2.b;	 Catch:{ all -> 0x0069 }
        if (r0 < 0) goto L_0x004a;
    L_0x0005:
        r0 = r2.a;	 Catch:{ all -> 0x0069 }
        r0 = r0.isEmpty();	 Catch:{ all -> 0x0069 }
        if (r0 == 0) goto L_0x0011;
    L_0x000d:
        r0 = r2.b;	 Catch:{ all -> 0x0069 }
        if (r0 != 0) goto L_0x004a;
    L_0x0011:
        r0 = r2.b;	 Catch:{ all -> 0x0069 }
        if (r0 <= r3) goto L_0x0048;
    L_0x0015:
        r0 = r2.a;	 Catch:{ all -> 0x0069 }
        r0 = r0.isEmpty();	 Catch:{ all -> 0x0069 }
        if (r0 == 0) goto L_0x001e;
    L_0x001d:
        goto L_0x0048;
    L_0x001e:
        r0 = r2.a;	 Catch:{ all -> 0x0069 }
        r0 = r0.entrySet();	 Catch:{ all -> 0x0069 }
        r0 = r0.iterator();	 Catch:{ all -> 0x0069 }
        r0 = r0.next();	 Catch:{ all -> 0x0069 }
        r0 = (java.util.Map.Entry) r0;	 Catch:{ all -> 0x0069 }
        r1 = r0.getKey();	 Catch:{ all -> 0x0069 }
        r0.getValue();	 Catch:{ all -> 0x0069 }
        r0 = r2.a;	 Catch:{ all -> 0x0069 }
        r0.remove(r1);	 Catch:{ all -> 0x0069 }
        r0 = r2.b;	 Catch:{ all -> 0x0069 }
        r0 = r0 + -1;
        r2.b = r0;	 Catch:{ all -> 0x0069 }
        r0 = r2.e;	 Catch:{ all -> 0x0069 }
        r0 = r0 + 1;
        r2.e = r0;	 Catch:{ all -> 0x0069 }
        monitor-exit(r2);	 Catch:{ all -> 0x0069 }
        goto L_0x0000;
    L_0x0048:
        monitor-exit(r2);	 Catch:{ all -> 0x0069 }
        return;
    L_0x004a:
        r3 = new java.lang.IllegalStateException;	 Catch:{ all -> 0x0069 }
        r0 = new java.lang.StringBuilder;	 Catch:{ all -> 0x0069 }
        r0.<init>();	 Catch:{ all -> 0x0069 }
        r1 = r2.getClass();	 Catch:{ all -> 0x0069 }
        r1 = r1.getName();	 Catch:{ all -> 0x0069 }
        r0.append(r1);	 Catch:{ all -> 0x0069 }
        r1 = ".sizeOf() is reporting inconsistent results!";
        r0.append(r1);	 Catch:{ all -> 0x0069 }
        r0 = r0.toString();	 Catch:{ all -> 0x0069 }
        r3.<init>(r0);	 Catch:{ all -> 0x0069 }
        throw r3;	 Catch:{ all -> 0x0069 }
    L_0x0069:
        r3 = move-exception;
        monitor-exit(r2);	 Catch:{ all -> 0x0069 }
        throw r3;
        */
        throw new UnsupportedOperationException("Method not decompiled: b.f.f.c(int):void");
    }

    public final synchronized String toString() {
        int i;
        i = this.f;
        int i2 = this.g + i;
        i = i2 != 0 ? (i * 100) / i2 : 0;
        return String.format(Locale.US, "LruCache[maxSize=%d,hits=%d,misses=%d,hitRate=%d%%]", new Object[]{Integer.valueOf(this.c), Integer.valueOf(this.f), Integer.valueOf(this.g), Integer.valueOf(i)});
    }
}
